<template>
    <div class="app-container">
  
      <div class="filter-container">
        <el-date-picker
          v-model="listQuery.date"
          type="date"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
          placeholder="选择日期">
        </el-date-picker>

        <el-select
          v-model="listQuery.pkg"
          style="width: 150px"
          class="filter-item"
        >
           <el-option label="全部包" :value="''" />
          <el-option v-for="(v, k) in pkgs" :key="k" :label="v" :value="k" />
          
        </el-select>
        <el-select
            v-model="listQuery.brand"
            clearable
            filterable
            style="width: 150px"
            class="filter-item"
            placeholder="厂商"
          >
          <el-option key="100" label="所有厂商" value=""></el-option>
          <el-option
            v-for="(v, k, index) in brand"
            :key="index"
            :label="v"
            :value="k"
          />
        </el-select>
        <el-input
          v-model="listQuery.oaid"
          placeholder="搜索oaid"
          style="width: 220px;"
          class="filter-item"
          @keyup.enter.native="handleFilter"
        />
        <el-input
          v-model="listQuery.type"
          placeholder="搜索type"
          style="width: 220px;"
          class="filter-item"
          @keyup.enter.native="handleFilter"
        />
        <el-button
         plain size="small"
          v-waves
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
        >搜索</el-button>

        <el-button
         plain size="small"
          v-waves
          class="filter-item btn"
          type="primary"
          icon="el-icon-refresh"
          @click="handleCancel"
        >重置</el-button>
      </div>
  
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
      >
      <el-table-column label="oaid" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{row.oaid }}</span>
          </template>
        </el-table-column>
        <el-table-column label="包" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{pkgs[row.pkg] }}</span>
          </template>
        </el-table-column>

        <el-table-column label="厂商" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{ row.brand }}</span> 
          </template>
        </el-table-column>
        
        <el-table-column label="type" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{ row.type }}</span> 
          </template>
        </el-table-column>

        <el-table-column label="信息" min-width="200" align="center">
          <template slot-scope="{row}">
            <span>{{ row.message }}</span> 
          </template>
        </el-table-column>

        <el-table-column label="创建时间" min-width="80" align="center">
          <template slot-scope="{row}">
            <span>{{ row.create_time }}</span>
          </template>
        </el-table-column>

      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        class="pageShow"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />

    </div>
  </template>
  
  <script>
  import {
    getBuryingPoint,
    getPkgList
  } from "@/api/adv_admin/config";
  import waves from "@/directive/waves"; // waves directive
  import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
  import {brand1} from '@/utils/index'
  
  export default {
    name: "Control",
    components: { Pagination },
    directives: { waves },
    data() {
      return {
        brand: brand1,
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          pkg: "",
          brand: '',
          date: '',
          type: ''
        },
        error_type: {},
        pkgs: {},
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
        },
      };
    },
    created() {
      this.getPkgs()
      this.getList();

    },
    methods: {
    
      getPkgs(){
        getPkgList().then((res)=>{
          this.pkgs = res.DATA.list
        })
      },
      getList() {
        this.listLoading = true;
        getBuryingPoint(this.listQuery).then((response) => {
          this.list = response.DATA.list;
          this.total = response.DATA.total;
          this.listLoading = false;
        });
      },
      handleFilter() {
        this.listQuery.page = 1;
        this.getList();
      },
      handleCancel(){
        this.listQuery = {
          page: 1,
          limit: 20,
          pkg: "",
          brand: '',
          date: '',
          type: ''
        }
        this.getList()
      }
    
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 0;
    font-size: 16px;
    color: #ccc;
    cursor: pointer;
    user-select: none;
  }
  .push {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    margin-left: 5px;
  }
  .pageHidden {
    display: none;
  }
  .btn {
    margin-left: 0;
  }
  .fullwidth {
    width: 450px;
    margin-left: 50px;
  }
  @media (max-width: 550px) {
    .pageShow {
      display: none;
    }
    .pageHidden {
      display: block;
    }
    .fullwidth {
      width: 100%;
      margin-left: 0;
    }
  }
  </style>
  